using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class QuyenDAO
    {
        
        public static List<QuyenDTO> Select()
        {
            List<QuyenDTO> lst = new List<QuyenDTO>();
            try
            {
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spQuyenSelect");
                foreach (DataRow dr in dt.Rows)
                {
                    QuyenDTO qn = new QuyenDTO();
                    qn.MaQuyen = int.Parse(dr["MaQuyen"].ToString());
                    qn.Quyen = (dr["Quyen"].ToString());
                    lst.Add(qn);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return lst;
        }
        public static QuyenDTO SelectByID(int MaQuyen)
        {
            QuyenDTO qn = new QuyenDTO();
            try
            {
                List<SqlParameter> sqlparam = new List<SqlParameter>();
                sqlparam.Add(new SqlParameter("@MaQuyen", MaQuyen));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spQuyenSelectByID", sqlparam);
                DataRow dr = dt.Rows[0];
                qn.MaQuyen = int.Parse(dr["MaQuyen"].ToString());
                qn.Quyen = (dr["Quyen"].ToString());     
                
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return qn;
        }
        
    }
}
